package com.lrkj.property.controller;

import com.lrkj.property.vo.FloorVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.property.domain.Floor;
import com.lrkj.property.service.IFloorService;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.common.core.page.TableDataInfo;

/**
 * 楼栋信息Controller
 *
 * @author yajun_ren
 * @date 2021-07-22
 */
@Api(tags = "楼栋信息")
@RestController
@RequestMapping("/property/floor")
public class FloorController extends BaseController
{
    @Autowired
    private IFloorService floorService;

    /**
     * 查询楼栋信息列表
     */
    @ApiOperation(value = "查询楼栋信息列表", notes = "查询楼栋信息列表")
    @PreAuthorize("@ss.hasPermi('property:floor:list')")
    @GetMapping("/list")
    public TableDataInfo list(Floor floor)
    {
        startPage();
        List<Floor> list = floorService.selectFloorList(floor);
        return getDataTable(list);
    }

    /**
     * 导出楼栋信息列表
     */
	@ApiOperation(value = "导出楼栋信息列表", notes = "导出楼栋信息列表")
    @PreAuthorize("@ss.hasPermi('property:floor:export')")
    @Log(title = "楼栋信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Floor floor)
    {
        List<Floor> list = floorService.selectFloorList(floor);
        ExcelUtil<Floor> util = new ExcelUtil<Floor>(Floor.class);
        return util.exportExcel(list, "楼栋信息数据");
    }

    /**
     * 获取楼栋信息详细信息
     */
	@ApiOperation(value = "获取楼栋信息详细信息", notes = "获取楼栋信息详细信息")
    @PreAuthorize("@ss.hasPermi('property:floor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(floorService.selectFloorById(id));
    }

    /**
     * 新增楼栋信息
     */
	  @ApiOperation(value = "新增楼栋信息", notes = "新增楼栋信息")
    @PreAuthorize("@ss.hasPermi('property:floor:add')")
    @Log(title = "楼栋信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Floor floor)
    {
        return toAjax(floorService.insertFloor(floor));
    }

    /**
     * 修改楼栋信息
     */
	 @ApiOperation(value = "修改楼栋信息", notes = "修改楼栋信息")
    @PreAuthorize("@ss.hasPermi('property:floor:edit')")
    @Log(title = "楼栋信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Floor floor)
    {
        return toAjax(floorService.updateFloor(floor));
    }

    /**
     * 删除楼栋信息
     */
	 @ApiOperation(value = "删除楼栋信息", notes = "删除楼栋信息")
    @PreAuthorize("@ss.hasPermi('property:floor:remove')")
    @Log(title = "楼栋信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(floorService.deleteFloorByIds(ids));
    }


    /**
     * 一键生成楼层数据
     */
    @ApiOperation(value = "一键生成楼层数据", notes = "一键生成楼层数据")
    @PreAuthorize("@ss.hasPermi('property:floor:generationUnitAndLayer')")
    @PostMapping("/generationUnitAndLayer")
    public AjaxResult generationUnitAndLayer(@RequestBody Floor floor){
        return toAjax(floorService.generationUnitAndLayer(floor));
    }


    /**
     * 新增楼栋数量
     */
    @ApiOperation(value = "新增楼栋数量", notes = "新增楼栋数量")
    @PreAuthorize("@ss.hasPermi('property:floor:addFloorNum')")
    @PostMapping("/addFloorNum")
    public AjaxResult addFloorNum(@RequestBody FloorVo floor){
        return toAjax(floorService.addFloorNum(floor));
    }


}
